// 主要是浏览器的常用缓存方法

// 设置localstorge缓存
const setLocalStorge = (key, value) => {
    localStorage.setItem(key, JSON.stringify(value))
}

// 获取localstorge缓存
const getLocalStorge = (key) => {
    const value = localStorage.getItem(key)
    try {
        return JSON.parse(value)
    } catch{
        return ''
    }
}

// 清除localstorge缓存
const clearLocalStorge = (key) => {
    localStorage.removeItem(key)
}

// 清除localstorge所有缓存
const clearAllLocalStorge = () => {
    localStorage.clear()
}

// 设置sessionStorage缓存
const setSessionStorage = (key, value) => {
    sessionStorage.setItem(key, JSON.stringify(value))
}

// 获取sessionStorage缓存
const getSessionStorage = (key) => {
    const value = sessionStorage.getItem(key)
    try {
        return JSON.parse(value)
    } catch{
        return ''
    }
}

// 清除sessionStorage缓存
const clearSessionStorage = (key) => {
    sessionStorage.removeItem(key)
}

// 清除sessionStorage所有缓存
const clearAllSessionStorage = () => {
    sessionStorage.clear()
}


export { setLocalStorge, clearLocalStorge, clearAllLocalStorge, getLocalStorge, setSessionStorage, clearSessionStorage, clearAllSessionStorage, getSessionStorage }